package com.example.fw;

import static org.junit.Assert.fail;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class WebDriverHelper {

	private static WebDriver driver;
	private StringBuffer verificationErrors = new StringBuffer();
	@SuppressWarnings("unused")
	private final ApplicationManager manager;

	public WebDriverHelper(ApplicationManager manager) {
		this.manager = manager;
		driver = new FirefoxDriver();
		driver.manage()
				.timeouts()
				.implicitlyWait(Integer.parseInt(manager.getProperty("10")),
						TimeUnit.SECONDS);
		driver.get(manager.getProperty("baseUrl"));

	}

	public void stop() {
		driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}

	public WebDriver getDriver() {
		return driver;
	}

}